package vn.gg.network;

import com.google.gson.Gson;

/**
 * Dung message dang json.
 * 
 * Bao gom 2 fields:
 * 
 * - c: command - d: data
 * 
 * @author truongps
 * 
 */
public class Message {
	/**
	 * The command of the message.
	 */
	String c;

	/**
	 * The data of the message.
	 */
	Object d;
	
	/**
	 * Gson parser.
	 */
	private static final Gson GSON = new Gson();

	public static Message createMessageFrom(String jsonString) {
		return GSON.fromJson(jsonString, Message.class);
	}
	
	public Message() {
		
	}

	public Message(String command) {
		this.c = command;
	}
	
	public Message(String command, Object data) {
		this.c = command;
		this.d = data;
	}
	
	public String getCommand() {
		return c;
	}
	
	public void setCommand(String command) {
		this.c = command;
	}
	
	public Object getData() {
		return d;
	}
	
	public void setData(Object data) {
		this.d = data;
	}
	
	/**
	 * 
	 * @return
	 */
	public String toJson() {
		return GSON.toJson(this);
	}
}
